<!-- $Id: topic_edit.htm 16992 2010-01-19 08:45:49Z wangleisvn $ -->

{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,selectzone.js,colorselector_topic.js"}
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
{if $warning}
<ul style="padding:0; margin: 0; list-style-type:none; color: #CC0000;">
  <li style="border: 1px solid #CC0000; background: #FFFFCC; padding: 10px; margin-bottom: 5px;" >{$warning}</li>
</ul>
{/if}
<!-- start goods form -->
<div class="tab-div">
  <!-- tab bar -->
  <div id="tabbar-div">
    <p>
    	<span class="tab-front" id="general-tab">通用信息</span>
    	<span class="tab-back" id="goods-tab">专题商品</span>
	</p>
  </div>
  <!-- tab body -->
  <div id="tabbody-div">
    <form action="second.php" method="post" name="theForm" enctype="multipart/form-data">
      <table cellspacing="1"  id="general-table" cellpadding="3" width="100%">
        <tr>
          <td class="label">专题名称</td>
          <td><input name="topic_name" type="text" value="{$topic.title}" size="40" />{$lang.require_field}</td>
        </tr>
        <tr>
          <td class="label">关键词</td>
          <td><textarea name="keywords" id="keywords" cols="40" rows="3">{$topic.keywords}</textarea></td>
        </tr>
        <tr>
          <td class="label">描述</td>
          <td><textarea name="description" id="description" cols="40" rows="5">{$topic.description}</textarea></td>
        </tr>
        <tr>
          <td class="label">简介</td>
          <td><textarea name="content" id="content" cols="40" rows="5">{$topic.content}</textarea>{$lang.require_field}<span class="notice-span" style="display:block">140字以内</span></td>
        </tr>
        <tr>
        <td class="label">上传图片</td>
        <td>
          <input type="file" name="img" size="35" />
          {if $topic.img}
            <a href="goods.php?act=show_image&img_url={$topic.img}" title="点击查看图片" target="_blank"><img src="images/yes.gif" border="0" /></a>
          {else}
            <img src="images/no.gif" />
          {/if}
          <span class="notice-span" style="display:block">800px * 310px</span>
        </td>
      </tr>
        <tr>
	        <td class="label">上传手机版图片</td>
	        <td>
	          <input type="file" name="img_wap" size="35" />
	          {if $topic.img_wap}
	            <a href="goods.php?act=show_image&img_url={$topic.img_wap}" title="点击查看图片" target="_blank"><img src="images/yes.gif" border="0" /></a>
	          {else}
	            <img src="images/no.gif" />
	          {/if}
	        </td>
	      </tr>
        <tr>
		    <td class="label">秒杀开始时间</td>
		    <td>
		      <input name="start_time" type="text" id="start_time" size="22" value='{$topic.start_time}' readonly="readonly" />
		      <input name="selbtn1" type="button" id="selbtn1" onclick="return showCalendar('start_time', '%Y-%m-%d %H:%M', '24', false, 'selbtn1');" value="{$lang.btn_select}" class="button"/>
		    </td>
		  </tr>
		  <tr>
		    <td class="label">秒杀结束时间</td>
		    <td>
		      <input name="end_time" type="text" id="end_time" size="22" value='{$topic.end_time}' readonly="readonly" />
		      <input name="selbtn2" type="button" id="selbtn2" onclick="return showCalendar('end_time', '%Y-%m-%d %H:%M', '24', false, 'selbtn2');" value="{$lang.btn_select}" class="button"/>
		    </td>
		  </tr>
      </table>
      <table width="90%" border="0"  align="center" cellpadding="0" cellspacing="0" id="goods-table" style="display:none;" >
        <tr>
          <td colspan="3"><img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
            <select name="cat_id2">
              <option value="0">{$lang.all_category}</option>
              {$cat_list}
            </select>
            <select name="brand_id2">
              <option value="0">{$lang.all_brand}</option>
              {html_options options=$brand_list}
            </select>
            <input type="text" name="keyword2"/>
            <input name="button" type="button" class="button" onclick="searchGoods('cat_id2', 'brand_id2', 'keyword2')" value="{$lang.button_search}" />          </td>
        </tr>
        <!-- 商品列表 -->
        <tr height="37">
          <th>{$lang.all_goods}</th>
          <th>{$lang.handler}</th>
          <th>{$lang.selected_goods}</th>
        </tr>
        <tr>
          <td width="42%">
          	<select name="source_select" id="source_select" size="20" style="width:100%;height:300px;"  ondblclick="addItem(this)" onchange="selectSource(this)">
            </select>
          </td>
          <td align="center">
          	<p>商品价格<br /><input id="price" name="price" type="text" size="6" value=""/></p>
          	<p>商品数量<br /><input id="number" name="number" type="text" size="6" value=""/></p>
          	<!-- <p>
              <input name="button" type="button" class="button" onclick="addAllItem(document.getElementById('source_select'))" value="&gt;&gt;" />
            </p> -->
            <p>
              <input name="button" type="button" class="button" onclick="addItem(document.getElementById('source_select'))" value="&gt;" />
            </p>
            <p>
              <input name="button" type="button" class="button" onclick="removeItem(document.getElementById('target_select'))" value="&lt;" />
            </p>
            <p>
              <input name="button" type="button" class="button" value="&lt;&lt;" onclick="removeItem(document.getElementById('target_select'), true)" />
            </p></td>
          <td width="42%">
          	<select name="target_select" id="target_select" size="20" style="width:100%;height:300px" multiple="multiple">
          	
            </select>
          </td>
        </tr>
      </table>
      <div class="button-div">
        <input  name="second_data" type="hidden" id="second_data" value='' />
        <input  name="act" type="hidden" id="act" value='{$act}' />
        <input  name="second_id" type="hidden" id="second_id" value='{$topic.second_id}' />
        <input type="submit"  name="Submit"       value="{$lang.button_submit}" class="button" onclick="return checkForm()"/>
        <input type="reset"   name="Reset"        value="{$lang.button_reset}" class="button"/>
      </div>
    </form>
  </div>
</div>
{insert_scripts files="validator.js,tab.js"}
<script type="Text/Javascript" language="JavaScript">
<!--
var myTopic = {$topic.data};

{literal}



onload = function()
{
  
  // 开始检查订单
  startCheckOrder();
  
  showTargetList();
}


function checkForm()
{
  var validator = new Validator('theForm');
  validator.required('topic_name', '专题名称不能为空');
  validator.required('content', '简介不能为空');
  validator.required('start_time', '开始时间不能为空');
  validator.required('end_time', '结束时间不能为空');
  validator.islt('start_time', 'end_time', '开始时间必须小于结束时间');

  document.getElementById("second_data").value = myTopic.toJSONString();

  return validator.passed();
}


function searchGoods(catId, brandId, keyword)
{
  var elements = document.forms['theForm'].elements;
  var filters = new Object;
  filters.cat_id = elements[catId].value;
  filters.brand_id = elements[brandId].value;
  filters.keyword = Utils.trim(elements[keyword].value);
  Ajax.call("second.php?act=get_goods_list", filters, function(result)
  {
    clearOptions("source_select");
    var obj = document.getElementById("source_select");
    for (var i=0; i < result.content.length; i++)
    {
      var opt   = document.createElement("OPTION");
      opt.value = result.content[i].value;
      opt.text  = result.content[i].text;
      opt.id    = result.content[i].data;
      opt.setAttribute('data-num',result.content[i].num);
      obj.options.add(opt);
    }
  }, "GET", "JSON");
}

function clearOptions(id)
{
  var obj = document.getElementById(id);
  while(obj.options.length>0)
  {
    obj.remove(0);
  }
}

function selectSource(e)
{
	document.getElementById('price').value = e.options[e.selectedIndex].id;
	document.getElementById('number').value = e.options[e.selectedIndex].getAttribute('data-num');
}

function addAllItem(sender)
{
  if(sender.options.length == 0) return false;
  for (var i = 0; i < sender.options.length; i++)
  {
    var opt = sender.options[i];
    addItem(null, opt.value, opt.text, opt.id);
  }
}

function addItem(sender, value, text, id)
{
  var target_select = document.getElementById("target_select");
  
  var newOpt   = document.createElement("OPTION");
  if (sender != null)
  {
    if(sender.options.length == 0) return false;
    var option = sender.options[sender.selectedIndex];
    var price = document.getElementById("price").value;
    var number = document.getElementById("number").value;
    newOpt.value = option.value;
    newOpt.text  = option.text+' -- [单价'+price+'][数量'+number+']';
    newOpt.id  = price;
  }
  else
  {
    newOpt.value = value;
    newOpt.text  = text;
    newOpt.id  = id;
  }
  if (targetItemExist(newOpt)) return false;
  /* if (target_select.length>=50)
  {
    alert(item_upper_limit);
  } */
  target_select.options.add(newOpt);
  
  if(!myTopic)
  {
    myTopic = new Array();
  }
  myTopic.push(newOpt.text + "|" + newOpt.value + "|" + newOpt.id + "|" + number);
  
}

// 商品是否存在
function targetItemExist(opt)
{
  var options = document.getElementById("target_select").options;
  for ( var i = 0; i < options.length; i++)
  {
    if(options[i].value == opt.value) 
    {
      return true;
    }
  }
  return false;
}



function showTargetList()
{
  clearOptions("target_select");
  for ( var i = 0; i < myTopic.length; i++)
  {
    var newOpt    = document.createElement("OPTION");
    var arr = myTopic[i].split('|');
    newOpt.value  = arr[1];
    newOpt.text   = arr[0];
    document.getElementById("target_select").options.add(newOpt);
  }
}

function removeItem(sender,isAll)
{
  
  var key = 'default';
  
  var arr = myTopic;
  if (!isAll)
  {
	if(typeof(sender.options[sender.selectedIndex])=='undefined'){
		alert('请选择项目');
	}
	else{
		var goodsName = sender.options[sender.selectedIndex].text;
	    for (var j = 0; j < arr.length; j++)
	    {
	      if (arr[j].indexOf(goodsName) >= 0)
	      {
	          myTopic.splice(j,1);
	      }
	    }

	    for (var i = 0; i < sender.options.length;)
	    {
	      if (sender.options[i].selected) {
	        sender.remove(i);
	        myTopic.splice(i, 0);
	      }
	      else
	      {
	        i++;
	      }
	    }
	}
    
  }
  else
  {
    myTopic = new Array();
    sender.innerHTML = "";
  }
}

/**
 * 判断当前浏览器类型
 */
function navigator_type()
{
  var type_name = '';

  if (navigator.userAgent.indexOf('MSIE') != -1)
  {
    type_name = 'IE'; // IE
  }
  else if(navigator.userAgent.indexOf('Firefox') != -1)
  {
    type_name = 'FF'; // FF
  }
  else if(navigator.userAgent.indexOf('Opera') != -1)
  {
    type_name = 'Opera'; // Opera
  }
  else if(navigator.userAgent.indexOf('Safari') != -1)
  {
    type_name = 'Safari'; // Safari
  }
  else if(navigator.userAgent.indexOf('Chrome') != -1)
  {
    type_name = 'Chrome'; // Chrome
  }

  return type_name;
}
{/literal}
//-->
</script>
{include file="pagefooter.htm"}
